﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_Tra_back_goodChange : System.Web.UI.Page
{
    static string strSql, GoodsId, projectid, ProductCode, companyName_Agent, UserCode_sc, SortId, SpellingCode;
    static int ProductId, AccountId_SC, AccountId_Agent;
    protected void Page_Load(object sender, EventArgs e)
    {
        GoodsId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["GoodsId"]));
        projectid = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["projectid"]));
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                Db db = new Db();
                System.Data.IDataReader dr;
                strSql = "select GoodsId,ProductName,ProductId,ProductCode,GoodsName,Medicinemodel,Outlookc,Unit,AccountId_SC,UserCode,SortId,CompanyName,Pack,Factor,PackUnit,QualityLevels,AccountId_Agent,companyName_Agent,SpellingCode from v_product_goods where GoodsID=" + GoodsId;
                dr = db.DataReader(strSql);
                while (dr.Read())
                {
                    labgoodscode.Text = dr["GoodsId"].ToString();
                    labgoodname.Text = dr["GoodsName"].ToString();
                    labType.Text = dr["Medicinemodel"].ToString();
                    labProductname.Text = dr["ProductName"].ToString();
                    laboutlook.Text = dr["Outlookc"].ToString();
                    Labunit.Text = dr["Unit"].ToString();
                    Labpack.Text = dr["Pack"].ToString();
                    Labfactor.Text = dr["Factor"].ToString();
                    LabCompanyName_SC.Text = dr["CompanyName"].ToString();
                    LabPackUnit.Text = SysFun.ToTrim(dr["PackUnit"]);
                    txtCompanyName_PS.Text = "请选择配送企业";
                    rdoQualityLevels.SelectedValue = SysFun.ToTrim(dr["QualityLevels"]);
                    ProductCode = SysFun.ToTrim(dr["ProductCode"]);
                    ProductId = Convert.ToInt32(dr["ProductId"]);
                    AccountId_SC = Convert.ToInt32(dr["AccountId_SC"]);
                    AccountId_Agent = Convert.ToInt32(dr["AccountId_Agent"]);
                    companyName_Agent = SysFun.ToTrim(dr["companyName_Agent"]);
                    UserCode_sc = SysFun.ToTrim(dr["UserCode"]);
                    SortId = SysFun.ToTrim(dr["SortId"]);
                    SpellingCode = SysFun.ToTrim(dr["SpellingCode"]);
                }
                dr.Close();
                dr.Dispose();
                db.Close();
            }
        }
    }
    protected void Button2_ServerClick(object sender, EventArgs e) //添加到总配送目录表
    {
        if (txtCompanyName_PS.Text.Contains("请选择配送企业") == true)
        {
            Response.Write("<script>alert('您还没有选择配送企业，不能添加！');</script>");
        }
        else
        {
            Db db = new Db();
            System.Data.IDataReader dr;
            //根据ProductId 查找该商品的类别id 、类别名、大类id和大类名　
            dr = db.DataReader("SELECT Product.SortId, product_sort.SortName as SortName ,product_sort.FrontSortId as FrontSortId, product_sort_1.SortName AS FrontSortName FROM Product INNER JOIN " +
                            "product_sort ON Product.SortId = product_sort.SortId INNER JOIN product_sort product_sort_1 ON product_sort.FrontSortId = product_sort_1.SortId where Product.ProductId =" + ProductId );
            dr.Read();
            strSql = "insert into SupplyPlan_Goods values(" + projectid + "," + ProductId + ",'" + labProductname.Text + "','" + labType.Text + "','" + laboutlook.Text + "','" +
                      Labunit.Text + "','" + ProductCode + "',null,null,null," + labgoodscode.Text + ",'" + labgoodname.Text + "'," + rdoQualityLevels.SelectedValue + ",'" + Labpack.Text + "'," +
                       Labfactor.Text + ",'" + LabPackUnit.Text + "'," + AccountId_SC + ",'" + LabCompanyName_SC.Text + "','" + UserCode_sc + "'," + AccountId_Agent + ",'" + companyName_Agent + "',null,null,null," +
                       txtAccountId_PS.Value + ",'" + txtCompanyName_PS.Text + "','" + TextPs_UserCode.Text + "','" + BidPrice.Text + "',null,1,1,null,null," + Convert.ToInt32(dr["FrontSortId"]) + ",'" + SysFun.ToTrim(dr["FrontSortName"]) + "'," + SortId + ",'"
                       + SysFun.ToTrim(dr["SortName"]) + "',null,null,null,null,null,null,'a','a',0,'" + SpellingCode + "')";
            dr.Close();
            db.Command(strSql);
            dr.Close();
            dr.Dispose();
            db.Close();
            Response.Write(@"<script language='javascript'>alert('添加成功！2秒钟后页面将自动关闭');setTimeout('self.close()',2000);</script>");
            Response.Write(@"<script lannguage='javascript'>window.opener.location.href='Tra_back_good.aspx?projectid=" + projectid + "'</script>");

        }

    }
    protected void BidPrice_TextChanged(object sender, EventArgs e)
    {

    }
}
